package com.huan.study.mybatis.controller;

import com.huan.study.mybatis.entity.Customer;
import com.huan.study.mybatis.service.CustomerService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * @author YanXxx
 */
@RestController
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @GetMapping("addCustomer")
    public String addCustomer(@RequestParam("phone") String phone, @RequestParam("address") String address) {
        Customer customer = new Customer();
        customer.setAddress(address);
        customer.setPhone(phone);
        customer.setAge(18);
        int result = customerService.addCustomer(customer);
        return "添加结果: " + result;
    }

    @GetMapping("batchInset")
    public Integer batchInsert() {
        List<Customer> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Customer customer = new Customer();
            customer.setAge(i);
            customer.setPhone("1" + i);
            customer.setAddress("address" + i);
            list.add(customer);
        }
        return customerService.batchInsert(list);
    }

    @PostMapping("findCustomer")
    public Customer findCustomer(@RequestBody Customer customer) {
        return customerService.findCustomer(customer);
    }

    @PostMapping("findCustomerList")
    public List<Customer> findCustomerList(@RequestBody Customer customer) {
        return customerService.findCustomerList(customer);
    }

    @PostMapping("findCustomerListMap")
    public List<Map> findCustomerListMap(@RequestBody Customer customer) {
        return customerService.findCustomerListMap(customer);
    }
}
